<%--
  Created by IntelliJ IDEA.
  User: 86180
  Date: 2021/2/5
  Time: 10:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>

<html class="app-ui">

<head>
    <!-- Meta -->
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />

    <!-- Document title -->
    <title>我的收获地址</title>

    <meta name="description" content="AppUI - Frontend Template & UI Framework" />
    <meta name="robots" content="noindex, nofollow" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/assets/css/bootstrap.min.css">
    <!-- Favicons -->
    <link rel="apple-touch-icon" href="${pageContext.request.contextPath}/assets/img/favicons/apple-touch-icon.png" />
    <link rel="icon" href="${pageContext.request.contextPath}/assets/img/favicons/favicon.ico" />

    <!-- AppUI CSS stylesheets -->
    <link rel="stylesheet" id="css-font-awesome" href="${pageContext.request.contextPath}/assets/css/font-awesome.css" />
    <link rel="stylesheet" id="css-ionicons" href="${pageContext.request.contextPath}/assets/css/ionicons.css" />
    <link rel="stylesheet" id="css-bootstrap" href="${pageContext.request.contextPath}/assets/css/bootstrap.css" />
    <link rel="stylesheet" id="css-app" href="${pageContext.request.contextPath}/assets/css/app.css" />
    <link rel="stylesheet" id="css-app-custom" href="${pageContext.request.contextPath}/assets/css/app-custom.css" />
    <!-- End Stylesheets -->
</head>
<body class="app-ui layout-has-fixed-header">
<div class="app-layout-canvas">
    <div class="app-layout-container">

        <!-- Header -->
        <header class="app-layout-header">
            <nav class="navbar navbar-default col-lg-offset-1">
                <div class="container-fluid">
                    <div class="navbar-header">
                        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#header-navbar-collapse"
                                aria-expanded="false">
                            <span class="sr-only">Toggle navigation</span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                        </button>
                        <button class="pull-left hidden-lg hidden-md navbar-toggle" type="button" data-toggle="layout" data-action="sidebar_toggle">
                            <span class="sr-only">Toggle drawer</span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                        </button>
                        <a class="navbar-brand" href="javascript:void(0)">
                            <img class="img-responsive" src="${pageContext.request.contextPath}/assets/img/logo/logo-frontend.png" title="强强组合商城" alt="AppUI" />
                        </a>
                    </div>

                    <div class="collapse navbar-collapse" id="header-navbar-collapse">
                        <ul id="main-menu" class="nav navbar-nav navbar-left">

                            <li class="active">
                                <a href="${pageContext.request.contextPath}/jsp/home/frontend_home.jsp">首页</a>
                            </li>

                            <li>
                                <a href="frontend_about.html">关于</a>
                            </li>

                            <li>
                                <a href="frontend_pricing.html">Pricing</a>
                            </li>

                            <li>
                                <a href="frontend_team.html">Team</a>
                            </li>

                            <li class="dropdown">
                                <a href="#" data-toggle="dropdown">分类 <span class="caret"></span></a>
                                <ul class="dropdown-menu">

                                    <li>
                                        <a href="frontend_search.html">Search</a>
                                    </li>

                                    <li>
                                        <a href="frontend_support.html">Support</a>
                                    </li>

                                    <li>
                                        <a href="frontend_contact.html">Contact</a>
                                    </li>

                                    <li>
                                        <a href="frontend_login_signup.html">Login / Signup</a>
                                    </li>

                                    <li>
                                        <a href="frontend_400.html">Error 400</a>
                                    </li>

                                </ul>
                            </li>

                        </ul>
                        <!-- .navbar-left -->

                        <ul class="nav navbar-nav navbar-right navbar-toolbar hidden-sm hidden-xs w-30">
                            <li class="active" id="business">
                                <a href="frontend_home.html">注册为商家</a>
                            </li>
                            <li class="active" id="deliver">
                                <a href="frontend_home.html">注册为配送员</a>
                            </li>
                            <li class="dropdown">
                                <a href="javascript:void(0)" data-toggle="dropdown"><i class="ion-ios-bell"></i> <span class="badge">3</span></a>
                                <ul class="dropdown-menu dropdown-menu-right">
                                    <li class="dropdown-header">消息</li>
                                    <li>
                                        <a tabindex="-1" href="javascript:void(0)"><span class="badge pull-right">3</span> 有无内鬼？ </a>
                                    </li>
                                    <li>
                                        <a tabindex="-1" href="javascript:void(0)"><span class="badge pull-right">1</span> 不过如此 </a>
                                    </li>
                                    <li class="divider"></li>
                                    <li class="dropdown-header">公告</li>
                                    <li>
                                        <a tabindex="-1" href="javascript:void(0)">登dua郎..</a>
                                    </li>
                                </ul>
                            </li>

                            <li class="dropdown dropdown-profile">
                                <a href="javascript:void(0)" data-toggle="dropdown">
                                    <span class="m-r-sm">${account.accName}<span class="caret"></span></span>
                                    <img class="img-avatar img-avatar-48" src="${pageContext.request.contextPath}/file/acc/${account.accImg == null?"000000011612245316757212.png":account.accImg}" alt="User profile pic" />
                                </a>
                                <ul class="dropdown-menu dropdown-menu-right">
                                    <li>
                                        <a href="${pageContext.request.contextPath}/jsp/MyAccount/MyMoneyRecord.jsp">个人账户</a>
                                    </li>
                                    <li>
                                        <a href="${pageContext.request.contextPath}/jsp/MyAccount/myBuyCart.jsp">我的购物车</a>
                                    </li>
                                    <li>
                                        <a href="#" id="logout">退出</a>
                                    </li>
                                </ul>
                            </li>
                        </ul>
                        <!-- .navbar-right -->
                    </div>
                </div>
                <!-- .container-fluid -->
            </nav>
            <!-- .navbar -->
        </header>
        <br />
        <br />
        <br />
        <main class="app-layout-content">

            <!-- Page Content -->
            <div class="container-fluid p-y-md">
                <!-- Forms Row -->
                <div class="row">
                    <div class=" col-lg-8 col-md-offset-2">
                        <!-- Material Forms Validation -->
                        <div class="card">
                            <div class="card-header">
                                <h4 id="MyAddress">新增收获地址</h4>
                                <ul class="card-actions">
                                    <li>
                                        <button type="button"><i class="ion-more"></i></button>
                                    </li>
                                </ul>
                            </div>
                            <div class="card-block">
                                <!-- jQuery Validation (.js-validation-material class is initialized in js/pages/base_forms_validation.js) -->
                                <!-- For more examples please check https://github.com/jzaefferer/jquery-validation -->
                                <form class="js-validation-material form-horizontal m-t-sm" action="" method="post">
                                    <div class="form-group">
                                        <div class="col-sm-9">
                                            <div class="form-material">
                                                <input class="form-control" type="text" id="val-username2" name="val-username2" placeholder="起一个好名字..." />
                                                <label for="val-username2">联系人</label>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-12">
                                            <div class="form-material">
                                                <textarea class="form-control" id="val-suggestions2" name="val-suggestions2" rows="3" placeholder="去哪里收获 ..."></textarea>
                                                <label for="val-suggestions2">详细收获地址</label>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-9">
                                            <div class="form-material">
                                                <input class="form-control" type="text" id="val-number2" name="val-number2" placeholder="8888-8888">
                                                <label for="val-number2">联系人电话</label>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group m-b-0 text-center">
                                        <div class="col-xs-12">
                                            <button class="btn btn-app" type="submit" style="width: 100px;" id="ensureEditAddress"> 确认</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <!-- .card-block -->
                        </div>
                        <!-- .card -->
                        <!-- End Material Forms Validation -->
                    </div>
                    <!-- .col-lg-6 -->

                </div>
                <!-- .row -->
                <!-- End Forms Row -->


            </div>
            <!-- End Page Content -->

        </main>

        <footer class="app-layout-footer">
            <!-- .section -->

            <div class="section p-y-xl bg-app bg-inverse">
                <div class="container text-center">
                    <!-- .row -->
                    <div class="row p-t-md p-b-lg">
                        <div class="col-md-10 col-md-offset-1">
                        </div>
                    </div>
                    <!-- .row -->
                </div>
                <!-- .container -->
            </div>
            <!-- .section -->
        </footer>

    </div>
    <!-- .app-layout-container -->
</div>

<!-- AppUI Core JS: jQuery, Bootstrap, slimScroll, scrollLock and App.js -->
<script src="${pageContext.request.contextPath}/assets/js/core/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/core/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/core/jquery.slimscroll.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/core/jquery.scrollLock.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/core/jquery.placeholder.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/app.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/app-custom.js"></script>
<!-- Page JS Plugins -->
<script src="${pageContext.request.contextPath}/assets/js/plugins/jquery-validation/jquery.validate.min.js"></script>

<!-- Page JS Code -->
<script src="${pageContext.request.contextPath}/assets/js/pages/base_forms_validation.js"></script>

<script type="text/javascript">
    $(function (){
        var accId = ${account.accId};
        var ordId = eval(${param.ordId});
        var reAddressId = eval(${param.reAddressId});
        var isAddaddress = ${param.isAddaddress};//值为1024代表从订单里修改收获地址，512代表新增，值为128代表从账户Id修改，64代表新增
        /*  修改我的收获地址    */
        function updateReAddressInfo() {
            var url = "${pageContext.request.contextPath}/accountInfo/updateMyReAddress";
            var receiveAddress = {
                reAddressId:reAddressId,
                accId:accId,
                reAddress:$("#val-suggestions2").val(),
                reLinkman:$("#val-username2").val(),
                reTelephone:$("#val-number2").val(),
                _method:"put"
            };
            $.post(url,receiveAddress,function (data) {
                if (data.code == 1001){
                    alert("修改成功");
                    if (isAddaddress == 1024 || isAddaddress == 512){
                        window.location.href = "${pageContext.request.contextPath}/jsp/MyAccount/show_receiveaddress.jsp?ordId="+ordId;
                    }else {
                        window.location.href = "${pageContext.request.contextPath}/jsp/MyAccount/myReceiveAddress.jsp";
                    }
                }
            })
        }
        /*  新增收获地址    */
        function addReAddressInfo() {
            var url = "${pageContext.request.contextPath}/accountInfo/addMyReAddress";
            var receiveAddress = {
                accId:accId,
                reAddress:$("#val-suggestions2").val(),
                reLinkman:$("#val-username2").val(),
                reTelephone:$("#val-number2").val(),
            };
            $.post(url,receiveAddress,function (data) {
                if (data.code == 1001){
                    alert("新增成功");
                    if (isAddaddress == 1024 || isAddaddress == 512){
                        window.location.href = "${pageContext.request.contextPath}/jsp/MyAccount/show_receiveaddress.jsp?ordId="+ordId;
                    }else{
                        window.location.href = "${pageContext.request.contextPath}/jsp/MyAccount/myReceiveAddress.jsp";
                    }
                }
            })
        }

        $("#ensureEditAddress").click(function () {
            if ($("#val-suggestions2").val() == '' && $("#val-username2").val() == '' && $("#val-number2").val() == ''){
                return false;
            }
            if (isAddaddress == 1024 || isAddaddress == 128){
                updateReAddressInfo();
            }
            if (isAddaddress == 512 || isAddaddress == 64){
                addReAddressInfo();
            }
        });

        /*回显我的地址信息*/
        function getReAddressInfo() {
            var url = "${pageContext.request.contextPath}/accountInfo/selectReceiveAddressByReAddressId";
            var param = {
                reAddressId:reAddressId
            };
            $.get(url,param,function (data) {
                if (data.code == 1001){
                    $("#val-username2").val(data.receiveAddress.reLinkman);
                    $("#val-suggestions2").val(data.receiveAddress.reAddress);
                    $("#val-number2").val(data.receiveAddress.reTelephone);
                }
            });
        }
        /*动态显示首页头部*/
        var role = ${account.role};
        if(role == 2){
            $("#business").html("<a href='../business/UnFinishOrder.jsp'>商家后台</a>");
            $("#deliver").html("");
        }
        if(role == 3){
            $("#business").html("");
            $("#deliver").html("<a href='#'>配送员后台</a>");
        }
        if (isAddaddress == 1024 || isAddaddress == 128){
            $("#MyAddress").html("修改我的地址");
            getReAddressInfo();
        }
        if (isAddaddress == 512){
            $("#MyAddress").html("新增收获地址");
        }
        /*退出登录*/
        $("#logout").click(function (event){
            event.preventDefault();
            var url = "/login/logoutShop";
            $.post(url,function (){
                window.location.href = "../../login.jsp";
            })
        })


    });

</script>
</body>
</html>
